#include <stdio.h>
#include "process.h"
#include <unistd.h>
#include <string.h>
#define NUM 101
#define STYLE '#'

void FlushProcess(double total, double current){
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char *lable ="|-\\/";
    int len = strlen(lable);
    static int cnt = 0;
    for(int i = 0;i<current*100/total;i++){
        buffer[i]=STYLE;
    }
    double rate = current*1.0*100.0/total;
    cnt++;
    printf("[%-100s][%.1f%%][%c]\r",buffer,rate,lable[cnt%len]);
    fflush(stdout);
}

void process_v1(){
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char *lable ="|-\\/";
    int len = strlen(lable);
    int cnt = 0;
    while(cnt<=100){
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,lable[cnt%len]);
        fflush(stdout);
        buffer[cnt]=STYLE;
        cnt++;
        usleep(30000);
    }
    printf("\n");
}
